<?php defined('BASEPATH') OR exit('No direct script access allowed');

	class login_class extends CI_Model {
	
		public function chk_user_account($post) {
			$strEmail = stripslashes(filter_var($post['strEmail'], FILTER_SANITIZE_STRING));
			$strPassword = stripslashes(filter_var($post['strPassword'], FILTER_SANITIZE_STRING));

			$query = $this->db->get_where('jtn_users',array('strEmail'=>$strEmail))->result_array();
			$query = current($query);	

			if(trim($query['intID'])=="") {
				return "Email does not exist!";
			} elseif(trim($query['intDisabled'])==1) {
				return "Access denied.";
			} else {
				
				if(pw_unhash($query['strPassword']) == $strPassword)
				{
					$this->set_session($query);
					return "Thank you.";						
				}
				else
				{
					return "Password error.";
				}
			}			
		}
		public function set_session($user) {
			$this->session->set_userdata('owner',$user['strName']);	
			foreach($user as $key=>$value) {
				$this->session->set_userdata($key,$value);			
			}
			$this->session->set_userdata('user_logged_in',1);
		}
	} // end class
?>